<template>
  <basic-container>
    <avue-crud :option="option"
               :table-loading="loading"
               :data="data"
               :page.sync="page"  
               :search.sync="query"
               ref="crud" 
               id="crud"
               @search-change="searchChange"
               @search-reset="searchReset"
               @selection-change="selectionChange"
               @current-change="currentChange"
               @size-change="sizeChange"
               @refresh-change="refreshChange"
               @on-load="onLoad">     
      <template slot="createTimeSearch">
        <el-date-picker v-model="createTime" type="datetimerange" format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss" start-placeholder="开始时间" end-placeholder="结束时间"></el-date-picker>
      </template>
    </avue-crud> 
  </basic-container>
</template>

<script>
  import * as api from "@/api/record/record";
  import {mapGetters} from "vuex"; 
  import {init} from '@/mixins/init';  
  export default { 
    mixins: [init],
    data() {
      return {
        form: {},
        loading: true,
        page: {
          pageSize: 100,
          currentPage: 1,
          total: 0
        },
        createTime:[],
        title:'升级配置',
        showDialog: false,
        openType:'add',
        clickRow:null,
        selectionList: [],
        option: { 
          dialogWidth: '1000',
          labelWidth: 120,
          searchGutter: 0,
          menuWidth: 120,
          searchMenuSpan: 6,
          tip: false,
          border: true,
          index: true,
          viewBtn: false,
          editBtn: false,
          addBtn: false,
          delBtn: false,
          selection: true,
          menu:false,
          column: [
           {
              label: '日志名称',
              prop: 'logName',  
              width: 250,
              search: true
            },
            {
              label: "日志类型",
              prop: "logType",
              width: 120,
              search: false, 
            },
            {
              label: "日志内容",
              prop: "logTxt",              
              search: false, 
            },
            {
              label: "时间",
              prop: "createTime", 
              sortable: true,
              type: 'datetime',
              searchRange: true,
              width: 200,
              format: 'yyyy-MM-dd HH:mm:ss',
              valueFormat: 'yyyy-MM-dd HH:mm:ss',
              overHidden: true,
              search: true,
              searchslot: true 
            } 
          ]
        },
        data: []
      };
    },
    computed: {
      ...mapGetters(["permission"]),
      permissionList() {
        return {
          addBtn: false,
          viewBtn: false,
          delBtn: false,
          editBtn: false
        };
      },
      ids() {
        let ids = [];
        this.selectionList.forEach(ele => {
          ids.push(ele.id);
        });
        return ids.join(",");
      }
    },
    methods: {
      searchReset() {
        this.query = {};
        this.onLoad(this.page);
      },
      searchChange(params, done) {
        this.query = params;
        this.page.currentPage = 1;
        this.onLoad(this.page, params);
        done();
      },
      selectionChange(list) {
        this.selectionList = list;
      },
      selectionClear() {
        this.selectionList = [];
        this.$refs.crud.toggleSelection();
      },
      currentChange(currentPage) {
        this.page.currentPage = currentPage;
      },
      sizeChange(pageSize) {
        this.page.pageSize = pageSize;
      },
      refreshChange() {
        this.onLoad(this.page, this.query);
      },
      onLoad(page, params = {}) {
        this.loading = true;
        Object.assign(params, this.query)
        console.log(params);
        if (this.createTime) {
          this.query.createTimeBegin = this.createTime[0]
          this.query.createTimeEnd = this.createTime[1]
        }       
        this.page.currentPage = 1; 

        api.getPage(page.currentPage, page.pageSize, this.query).then(res => { 
          const data = res.data.data;
          this.page.total = data.total;
          this.data = data.records;
          this.loading = false; 
        });
      }
    }
  };
</script>

<style>
</style>
